"""
目录配置模块

统一管理系统中的目录路径
"""

import os
from pathlib import Path

class DirectoryConfig:
    """目录配置类"""
    
    def __init__(self, base_dir=None):
        """初始化目录配置"""
        if base_dir is None:
            self.base_dir = Path(__file__).parent.parent
        else:
            self.base_dir = Path(base_dir)
        
        # 标准目录
        self.logs_dir = self.base_dir / 'logs'
        self.output_dir = self.base_dir / 'output'
        self.data_dir = self.base_dir / 'data'
        self.config_dir = self.base_dir / 'config'
        
        # 确保目录存在
        self._ensure_directories()
    
    def _ensure_directories(self):
        """确保所有目录都存在"""
        for directory in [self.logs_dir, self.output_dir, self.data_dir, self.config_dir]:
            directory.mkdir(exist_ok=True)
    
    def get_logs_path(self, filename=None):
        """获取日志文件路径"""
        if filename:
            return str(self.logs_dir / filename)
        return str(self.logs_dir)
    
    def get_output_path(self, filename=None):
        """获取输出文件路径"""
        if filename:
            return str(self.output_dir / filename)
        return str(self.output_dir)
    
    def get_data_path(self, filename=None):
        """获取数据文件路径"""
        if filename:
            return str(self.data_dir / filename)
        return str(self.data_dir)
    
    def get_config_path(self, filename=None):
        """获取配置文件路径"""
        if filename:
            return str(self.config_dir / filename)
        return str(self.config_dir)

# 全局实例
directories = DirectoryConfig()

# 便捷的函数
def get_logs_path(filename=None):
    """获取日志文件路径"""
    return directories.get_logs_path(filename)

def get_output_path(filename=None):
    """获取输出文件路径"""
    return directories.get_output_path(filename)

def get_data_path(filename=None):
    """获取数据文件路径"""
    return directories.get_data_path(filename)

def get_config_path(filename=None):
    """获取配置文件路径"""
    return directories.get_config_path(filename)